home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 282 < prev    next >
Encoding:
Text File  |  1996-08-06  |  4.2 KB  |  82 lines

  1. Newsgroups: comp.lang.c,comp.std.c
  2. Path: blackbush.xlink.net!slsv6bt!slsv6bt!kanze
  3. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  4. Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
  5. In-Reply-To: ENGR@GSSI.MV.COM's message of Thu, 1 Feb 1996 16:56:57 GMT
  6. Message-ID: <KANZE.96Feb2133347@slsvewt.lts.sel.alcatel.de>
  7. Sender: news@lts.sel.alcatel.de
  8. Organization: SEL
  9. References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM>
  10.     <TANMOY.96Jan29090518@qcd.lanl.gov> <DM3wEy.FHH@mv.mv.com>
  11. Date: 02 Feb 1996 12:33:45 GMT
  12.  
  13. In article <DM3wEy.FHH@mv.mv.com> ENGR@GSSI.MV.COM (Michael Furman)
  14. writes:
  15.  
  16. |> In article <TANMOY.96Jan29090518@qcd.lanl.gov>, tanmoy@qcd.lanl.gov says...
  17. |> >
  18. |> >In article <KANZE.96Jan29121956@slsvewt.lts.sel.alcatel.de>
  19. |> >kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes: 
  20. |> ><snip>
  21. |> >   I think the crux of Michael Furman's question lies therein.  Does the
  22. |> >   standard require a diagnostic if the function main is not of one of
  23. |> >   the two types given?
  24. |> >
  25.  
  26. |>   Not exactly. My question was not about diagnostics, but about usage
  27. |> of constructions that are not defined in standard.
  28. |> There are two kinds of undefined behavior:
  29. |> 1. When operation does not have any meaning. Example: assigning a value
  30. |>   to dereferenced incorrect pointer. In such cases sometimes it is very 
  31. |>   hard or impossible (at least on some platforms) to check it even at
  32. |>   execution time and it is really possible that hard disk will be
  33. |>   reformatted as a result of such operations.
  34. |> 2. When operation has meaning but can not be portable defined for all
  35. |>   platforms. Example: all number conversions that depends on internal
  36. |>   representation or some CPU specific (like rounding). But I have more
  37. |>   clear example: "asm" keyword. I found it is defined in C++ draft and
  38. |>   I believe it is defined in C standard. 
  39. |>   Was it inserted just to give programmers some way to implement undefined
  40. |>   behavior (with some chance to have disk reformatted)? I do not think so.
  41.  
  42. |> In C++ draft standard there are two words used in such cases: 
  43. |> "undefined behavior" and "implementation defined behavior" - and I think
  44. |> they are used accordingly for 1. and 2. As I understand now in C standard
  45. |> there is no such clear division. But it does not mean that the problem
  46. |> does not exist and I believe it is very wrong to claim that in every
  47. |> case where behavier is not defined by C standard we may loose all
  48. |> data from our hard disk!
  49.  
  50. I think that the C standard makes the same distinction.  In fact, in
  51. general, I find it clearer that the C++ standard in this regard
  52. (possibly due to the fact that it is finished, whereas the C++
  53. standard isn't, or to the fact that C is a significantly simpler
  54. language).
  55.  
  56. In fact, according to the standard, undefined behavior is just that:
  57. undefined.  The standard makes no constraints.  In real life, of
  58. course, implementations will behave in a somewhat more restricted
  59. manner.  Thus, for example, I think it is safe to say that on no real
  60. implementation will "i = i ++" actually reformat your disk (although
  61. the probablity of it doing what you want is significantly less than
  62. 1).  The standard does not try and determine exactly what might really
  63. happen in each distinct case of undefined behavior, however.
  64.  
  65. Note that implementations *are* allowed to offer extensions, and
  66. define undefined behavior in an implementation specific manner.  An
  67. implementation which defines, for example, that writing to the address
  68. 0 clears the screen, is perfectly legal.  If you write code uniquely
  69. for that implementation, and you have to clear the screen, you will
  70. dereference a null pointer.  If this is the only way of clearing the
  71. screen on said implementation, and your application requires clearing
  72. the screen, you will write code dereferencing a null pointer.
  73.  
  74. That doesn't make such code any less undefined with regards to the
  75. standard.
  76. --
  77. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  78. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  79. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  80.                 -- A la recherche d'une activitΘ dans une region francophone
  81.  
  82.